import { request } from '../../../api/request.js'
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';


Page({
    data: {
        orderid: null,
        o2otype: null,
        o2ostatus: null,
        detailList: {},//订单详情

    },

    onLoad: function (options) {
        this.setData({
            orderid: options.orderid,
            o2otype: options.o2otype,
            o2ostatus: options.o2ostatus
        })
        console.log(options)
        request({
            url: '/order/detail',
            method: "POST",
            data: {
                o2oType: this.data.o2otype,
                orderId: this.data.orderid
            },
        }).then(res => {
            console.log(res)
            this.setData({
                detailList: res.data,
            })
        })
    },
    // 复制单号
    copyOrder(e) {
        console.log(e)
        wx.setClipboardData({
            data: e.currentTarget.dataset.index,
            success(res) {
                wx.getClipboardData({
                    success(res) {
                        wx.showToast({
                            title: '复制成功'
                        })
                    }
                })
            }
        })
    },
    // 联系骑手
    phoneCall(e) {
        console.log(e.currentTarget.dataset.phonecall)
        if (e.currentTarget.dataset.phonecall !== '') {
            wx.makePhoneCall({
                phoneNumber: e.currentTarget.dataset.phonecall
            })
        } else {
            Toast('暂无骑手信息');
        }
    },
    // 联系客户
    customerPhone(e) {
        console.log(e.currentTarget.dataset.phonecall)
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phonecall
        })
    },
    _formatstatus(list) {
        return list.map(x => {
            if (x.status === 1) {
                x.status = "待接单"
            } else if (x.status === 2) {
                x.status = "预定单"
            } else if (x.status === 3) {
                x.status = "已接单"
            } else if (x.status === 4) {
                x.status = "配送中"
            } else if (x.status === 5) {
                x.status = "已催单"
            } else if (x.status === 6) {
                x.status = "售后"
            } else if (x.status === 7) {
                x.status = "交易成功"
            } else if (x.status === 8) {
                x.status = "已取消"
            }
        })
    },
})